home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / cresid.zip / CINT.ASM next >
Assembly Source File  |  1986-03-05  |  6KB  |  226 lines

  1.     TITLE    LC Interrupt trap routine
  2.     NAME    LCINT
  3.     INCLUDE DOS.MAC            ; BE SURE TO INCLUDE THE CORRECT
  4.                     ; DOS.MAC!!
  5.  
  6. ;****************************************************************************
  7. ;
  8. ; This is the heart of a C driven interrupt handler. This file was used to
  9. ; write a critical error handler that remained resident. (It replaced the
  10. ; "Abort, Retry, Ignore" prompt with a window.) This file can be adapted to
  11. ; any interrupt and any C routine with a little work. THIS HAS BEEN USED ONLY
  12. ; IN THE S MODEL.
  13. ;
  14. ;****************************************************************************
  15.  
  16. DOS_INT        EQU 24H            ; int to be replaced
  17.  
  18. WRITE_INT    EQU 25H            ; DOS write int vector
  19. READ_INT    EQU 35H            ; DOS read int vector
  20.  
  21. XREG    STRUC
  22. REG_AX    DW    ?            ; general purpose registers
  23. REG_BX    DW    ?             
  24. REG_CX    DW    ?
  25. REG_DX    DW    ?
  26. REG_SI    DW    ?
  27. REG_DI    DW    ?
  28. XREG    ENDS
  29.  
  30. SREGS    STRUC
  31. REG_ES    DW    ?            ; segment registers
  32. REG_CS    DW    ?
  33. REG_SS    DW    ?
  34. REG_DS    DW    ?
  35. SREGS    ENDS
  36.  
  37.     DSEG
  38.  
  39.     INT_REGS    XREG    <>        ; saved regs. at int time
  40.     INT_SEGREGS    SREGS    <>        ; saved seg. regs.
  41.     EXTRN        _TOP:WORD        ; declared by C.ASM -- points
  42.                         ; to top of stack
  43.     ENDDS
  44.  
  45.     EXTRN    INTTIME:NEAR            ; your int routine goes here!
  46.  
  47.     PSEG
  48. ;;
  49. ; interrupt time data storage
  50. ;;
  51. C_ENVIRONMENT_DS DW ?            ; filled by int init, used...
  52. C_ENVIRONMENT_ES DW ?            ; ...to recreate C environment
  53. C_ENVIRONMENT_SS DW ?
  54. C_ENVIRONMENT_SP DW ?
  55.  
  56. INT_TIME_ES    DW ?
  57. INT_TIME_DS    DW ?            ; temp save of DS at int time
  58. INT_TIME_SI    DW ?              ; temp save of SI at int time
  59.  
  60. INT_TIME_BP    DW ?             ; added to account for no BP or SP...
  61. INT_TIME_SP    DW ?             ; ...in above structures
  62.  
  63. RETURN_VALUE    DW ?            ; return value from C service routine
  64.  
  65. DOS_SERVICE    DD ?            ; address of DOS Service routine
  66. INT_TWOONE    DD ?            ; old INT 21 vector
  67.  
  68. INT_IN_PROGRESS DB ?            ; interrupt in progress flag -- not
  69.                     ; used here 'cause int 24H cannot be
  70.                     ; recursive!
  71.  
  72. ;;**************************************************************************
  73. ; name        LC_SERVICE_INT
  74. ;
  75. ; description    Entered at (software) interrupt time, this routine
  76. ;        restores the C enviroment and processes the interrupt
  77. ;        trapping all references to the quad file
  78. ;;
  79.  
  80.     IF    LPROG
  81. LC_SERVICE_INT PROC    FAR
  82.     ELSE
  83. LC_SERVICE_INT PROC    NEAR
  84.     ENDIF
  85.  
  86.     MOV    CS:INT_IN_PROGRESS,1    ; clear int in progress flag
  87.  
  88.     MOV    CS:INT_TIME_ES,ES    ; save ES so it can be overwritten
  89.     MOV    CS:INT_TIME_DS,DS    ; save DS so it can be overwritten
  90.     MOV    CS:INT_TIME_SI,SI     ; save SI so it can be overwritten
  91.     MOV    CS:INT_TIME_BP,BP     ; save BP as structs do not have it
  92.     MOV    CS:INT_TIME_SP,SP     ; save SP as structs do not have it
  93.  
  94.     MOV    DS,CS:C_ENVIRONMENT_DS    ; set up C enviroment
  95.  
  96.     MOV    SI,OFFSET INT_REGS    ; point to input regs struct
  97.  
  98.     MOV    DS:[SI].REG_AX,AX    ; save general purpose regs
  99.     MOV    DS:[SI].REG_BX,BX
  100.     MOV    DS:[SI].REG_CX,CX
  101.     MOV    DS:[SI].REG_DX,DX
  102.     MOV    DS:[SI].REG_DI,DI
  103.     MOV    AX,CS:INT_TIME_SI    ; SI has been overwritten
  104.     MOV    DS:[SI].REG_SI,AX
  105.  
  106.     MOV    SI,OFFSET INT_SEGREGS    ; point to input segment regs struct
  107.  
  108.     MOV    AX,CS:INT_TIME_ES    ; ES has been overwritten
  109.     MOV    DS:[SI].REG_ES,AX
  110.     MOV    DS:[SI].REG_SS,SS
  111.     MOV    AX,CS:INT_TIME_DS    ; DS has been overwritten
  112.     MOV    DS:[SI].REG_DS,AX
  113.  
  114.     MOV    ES,CS:C_ENVIRONMENT_ES    ; complete C environment
  115.     MOV    SS,CS:C_ENVIRONMENT_SS
  116.     MOV    SP,CS:C_ENVIRONMENT_SP
  117.  
  118.     CALL    INTTIME            ; call the C routine
  119.     MOV    CS:RETURN_VALUE,AX    ; save return value
  120.     XOR    AX,AX
  121.  
  122.     MOV    SI,OFFSET INT_REGS    ; point to input regs struct
  123.  
  124.     MOV    AX,DS:[SI].REG_SI    ; SI needs to be saved while used
  125.     MOV    CS:INT_TIME_SI,AX
  126.  
  127.     MOV    AX,DS:[SI].REG_AX    ; restore general purpose regs
  128.     MOV    BX,DS:[SI].REG_BX
  129.     MOV    CX,DS:[SI].REG_CX
  130.     MOV    DX,DS:[SI].REG_DX
  131.     MOV    DI,DS:[SI].REG_DI
  132.  
  133.     MOV    SI,OFFSET INT_SEGREGS     ; point to input segment regs struct
  134.  
  135.     MOV    ES,DS:[SI].REG_DS    ; DS needs to be saved while used
  136.     MOV    CS:INT_TIME_DS,ES
  137.  
  138.     MOV    ES,DS:[SI].REG_ES
  139.     MOV    SS,DS:[SI].REG_SS
  140.  
  141.     MOV    SI,CS:INT_TIME_SI    ; restore pointing registers
  142.     MOV    DS,CS:INT_TIME_DS
  143.  
  144.     MOV    BP,CS:INT_TIME_BP    ; special BP restore
  145.     MOV    SP,CS:INT_TIME_SP    ; special SP restore
  146.  
  147.     MOV    CS:INT_IN_PROGRESS,0    ; clear int in progress flag
  148.  
  149.     MOV    AX,CS:RETURN_VALUE    ; move the return value
  150.     IRET                ; return from interrupt
  151.  
  152. LC_SERVICE_INT    ENDP
  153.  
  154. ;****************************************************************************
  155. ; description    set up the LC interrupt routines
  156. ;
  157. ;        INT_INIT -- Hooks into the specified int.
  158. ;        INT_TERM -- Unhooks (restores) the specified int.
  159. ;
  160. ; NOTE: INT_INIT must be called be int processing can begin...it saves the 
  161. ;       current C environment for use at interrupt time.
  162. ;;
  163.  
  164.         PUBLIC  INT_INIT
  165.         IF    LPROG
  166. INT_INIT    PROC    FAR
  167.         ELSE
  168. INT_INIT    PROC    NEAR
  169.         ENDIF
  170.  
  171.     PUSH    DS            ; save changed seg regs
  172.     PUSH    ES
  173.  
  174.     MOV    CS:C_ENVIRONMENT_DS,DS    ; save C environment for int time
  175.     MOV    CS:C_ENVIRONMENT_ES,ES
  176.     MOV    CS:C_ENVIRONMENT_SS,SS
  177.  
  178.     MOV    AX,_TOP            ; determine int time SP
  179.     SUB    AX,400H            ; gives 1024 byte stack
  180.     MOV    CS:C_ENVIRONMENT_SP,AX
  181.  
  182.     MOV    AH,READ_INT        ; read int vector function
  183.     MOV    AL,DOS_INT        ; specify DOS service vector
  184.     INT    21H
  185.  
  186.     MOV    WORD PTR CS:DOS_SERVICE+2,ES    ; save current vector
  187.     MOV    WORD PTR CS:DOS_SERVICE,BX
  188.  
  189.     LEA    DX,LC_SERVICE_INT    ; Use DOS to set new int address
  190.     PUSH    CS
  191.     POP    DS
  192.     MOV    AH,WRITE_INT
  193.     MOV    AL,DOS_INT
  194.     INT    21H
  195.  
  196.     POP    ES            ; restore changed seg regs
  197.     POP    DS
  198.     RET
  199.  
  200. INT_INIT    ENDP
  201.  
  202. ;********************* INT_TERM -- kill ints. *******************************
  203.  
  204.         PUBLIC INT_TERM
  205.         IF    LPROG
  206. INT_TERM    PROC    FAR
  207.         ELSE
  208. INT_TERM    PROC    NEAR
  209.         ENDIF
  210.  
  211.     PUSH    DS            ; DS gets changed
  212.  
  213.     MOV    DS,WORD PTR CS:DOS_SERVICE+2    ; Restore previous DOS service vector
  214.     MOV    DX,WORD PTR CS:DOS_SERVICE
  215.     MOV    AH,WRITE_INT
  216.     MOV    AL,DOS_INT
  217.     INT    21H
  218.  
  219.     POP    DS            ; restore DS
  220.     RET
  221. INT_TERM    ENDP
  222.  
  223.     ENDPS
  224.  
  225.     END
  226.